package Sudoku3.rules;
import Sudoku3.structure.bucket;
import Sudoku3.structure.cell;
import Sudoku3.structure.group;


public class rule04_hidden_single {
	
	//within a group, a value is only represented once
	public rule04_hidden_single(group g) {
				
		if (g instanceof bucket) { return; } //return if g is a bucket (this test is not valid).
		
		if (g.getSolvedCellCount() == 9) { return; } // return if the whole group is solved.
		
			
		//iterate values
		for (int i = 1; i < 10; i++) {
		
			try {
				if ( g.getPossible(i).cardinality() == 1) {
					//get the single cell that is possible for this value, ignore if it is already solved.
					cell c = g.get(g.getPossible(i).nextSetBit(0));
					if (!(c.isSolved())) {
						c.setValue(i);
						System.out.println("Rule 04:  Hidden Single Value(" + i + ") found in " + g.toString() + " for cell(" + c.toStringCoords() + ").");
					}
				}	
			} catch (Exception e) {
				e.printStackTrace();
			} 
		}
	}
}
